<script language="JavaScript" type="text/JavaScript">
  counter_kebutuhan = 0;
  function action_kebutuhan()
  {
    counterNextKebutuhan = counter_kebutuhan + 1;
    document.getElementById("newKebutuhan"+counter_kebutuhan).innerHTML = "<div class=\"form-row row-fluid\"><div class=\"span7 offset1\"><label>Bahan "+(counterNextKebutuhan+1)+"</label><input type=\"text\" id=\"nama_bahan_"+counterNextKebutuhan+"\" name=\"nama_bahan[]\" onfocus=\"myFunction(this)\" placeholder=\"Nama Bahan\" /></div><div class=\"span2 offset1\"><label>Jumlah</label><input type=\"text\" id=\"jumlah_"+counterNextKebutuhan+"\" name=\"jumlah[]\" placeholder=\"Jumlah\" /></div></div><div id=\"newKebutuhan"+counterNextKebutuhan+"\"></div>";
    counter_kebutuhan++;
  }
 </script>
 
 <script language="JavaScript" type="text/JavaScript">
  counter_langkah = 0;
  function action_langkah()
  {
    counterNextLangkah = counter_langkah + 1;
    document.getElementById("newLangkah"+counter_langkah).innerHTML = "<div class='form-row row-fluid'><div class='span11 offset1'><label>Langkah Kerja "+(counterNextLangkah+1)+"</label><input class='span11' type='text' name='langkah_kerja[]' placeholder='Langkah Kerja'></div></div><div id='newLangkah"+counterNextLangkah+"'></div>";
    counter_langkah++;
  }
 </script>
 
		<?php echo form_open($action,$form_attr);?>
                <!-- Build page from here: -->
                <div class="row-fluid">
                    <div class="span12">						
<!-- form data barang-->
						<div class="span4">
							<div class="box">
								<div class="title">
									<h4> 
										<span>Form Data Barang</span>
									</h4>			
								</div>
								<div class="content">
									<div class="form-row row-fluid">
										<div class="span12">
											<div class="row-fluid">
												<label class="form-label span5" for="maxlenght">ID Barang</label>
												<input class="span7" id="id_barang" name="id_barang" type="text" placeholder="ID Barang" maxlength="6" value="<?php echo (isset($barang['id_barang']))?$barang['id_barang']:'';?>" <?php echo $disable; ?> />
											</div>
										</div>
									</div>
									<input name="id" type="hidden" value="<?php echo (isset($barang['id_barang']))?$barang['id_barang']:'';?>"/>					
								<div class="form-row row-fluid">
									<div class="span12">
										<div class="row-fluid">
											<label class="form-label span5" for="normal">Nama Barang</label>
											<input class="span7" id="nama_barang" name="nama_barang" type="text" placeholder="Nama Barang" value="<?php echo set_value('nama_barang')?set_value('nama_barang'):$barang['nama_barang'];?>"/>
										</div>
									</div>
								</div>												
								<div class="form-row row-fluid">
									<div class="span12">
										<div class="row-fluid">
											<label class="form-label span5" for="checkboxes">Kategori</label>
											<div class="span7 controls"> 										
												<select id="id_kategori_barang" name="id_kategori_barang">
												<?php if($disable != ''){?>
												<option selected="selected" value="<?php echo $barang['id_kategori_barang'];?>"><?php echo $barang['nama_kategori_barang'];?></option>
												<?php }?>
												<?php foreach ($kategori_barang as $row){ ?>
													<option value="<?php echo $row->id_kategori_barang;?>"><?php echo $row->nama_kategori_barang;?></option>
												<?php } ?>										
												</select>										
											</div> 
										</div>
									</div> 
								</div>
							</div>
						</div><!-- End .box -->
					</div><!-- End .span6 -->
<!-- form langkah kerja -->		
					<div class="span4">
						<div class="box">
							<div class="title">
								<h4> 
									<span>Form Langkah Kerja</span>
								</h4>	
							</div>
							<div class="content">
<?php if($this->uri->segment(2)=="update"){
$i=1;
foreach($langkah_kerja as $row){
?>
								<div class="form-row row-fluid">
									<div class="span11 offset1">
									<label>Langkah Kerja <?php echo $i++;?></label>
									<input type="text" class="span11" name="langkah_kerja[]" placeholder="Langkah Kerja" value="<?php echo $row->nama_langkah_kerja;?>" disabled />
									</div>				
								</div>
<?php
	}
								echo "<div id='newLangkah0'></div>";
}
else{
?>
								<div class="form-row row-fluid">
									<div class="span11 offset1">
									<label>Langkah Kerja 1</label>
									<input type="text" class="span11" name="langkah_kerja[]" placeholder="Langkah Kerja" />
									</div>				
								</div>
								<div id="newLangkah0"></div>
<?php } ?>
								<div class="form-row row-fluid">
									<div class="offset1">
										<a href="javascript:action_langkah();" class="btn">Tambah</a>					
									</div>
								</div>
							</div>
						</div><!-- End .box -->
					</div><!-- End .span6 -->
<!-- form kebutuhan -->		
					<div class="span4">
						<div class="box">
							<div class="title">
								<h4> 
									<span>Form Kebutuhan</span>
								</h4>					
							</div>
							
							<div class="content">
<?php if($this->uri->segment(2)=="update"){
$i=1;
foreach($bahan as $row_bahan){
?>
								<div class="form-row row-fluid">
									<div class="span7 offset1">
									<label>Bahan <?php echo $i++;?></label>
									<input type="text" placeholder="Nama Bahan" value="<?php echo $row_bahan->nama_bahan;?>" disabled />
									</div>
									<div class="span2 offset1">
									<label>Jumlah</label>
									<input type="text" placeholder="Jumlah" value="<?php echo $row_bahan->jumlah_kebutuhan;?>" disabled />
									</div>
								</div>
<?php
	}
								echo "<div id='newLangkah0'></div>";
}
else{

									$arrNamaBahan = array();
									foreach ($nama_bahan_gudang as $row){
									$arrNamaBahan[] = $row->nama_bahan;
									}
?>
									
								<div class="form-row row-fluid">
									<div class="span7 offset1">
									<label>Bahan 1</label>
									<input type="text" id="nama_bahan_0" name="nama_bahan[]" onfocus="myFunction(this)" placeholder="Nama Bahan" />
									</div>
									<div class="span2 offset1">
									<label>Jumlah</label>
									<input type="text" id="jumlah_0" name="jumlah[]" placeholder="Jumlah" />
									</div>
								</div>
								<div id="newKebutuhan0"></div>
<?php
}
?>
								<div class="form-row row-fluid">
									<div class="offset1">
										<a href="javascript:action_kebutuhan();" class="btn">Tambah</a>					
									</div>
								</div>
							</div>
						</div><!-- End .box -->
					</div><!-- End .span6 -->	
				</div><!-- End .span8 -->					
			</div><!-- End .row-fluid -->

			<div class="row-fluid">
				<div class="span12">
					<div class="form-actions">
							<!-- Button to trigger modal --> 
							<button type="submit" class="btn btn-info">Simpan</button>
					</div>
				</div><!-- End .span8 -->					
			</div><!-- End .row-fluid -->
		</form>
<script type="text/javascript" src="<?php echo base_url();?>assets/plugins/forms/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/plugins/forms/uniform/jquery.uniform.min.js"></script>	

<script>
var arrNamaBahan = <?php echo json_encode($arrNamaBahan); ?>;
function myFunction(x){
var id = x.getAttribute("id");
//	alert(id);
	$("#"+id).autocomplete({
	  source: function( request, response ) {
			  var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
			  response( $.grep( arrNamaBahan, function( item ){
				  return matcher.test( item );
			  }) );
		  }
	});
}
</script>

	<script type="text/javascript">
		var disable = "<?php echo $disable;?>";
//		alert(disable);
        // document ready function
        $(document).ready(function() {
            $("input").not('.nostyle').uniform();
            $("#").validate({
                rules: {
					id_barang: {
						required: (disable != "disabled" ? true : false),
						minlength: 6,
						remote: (disable != "disabled" ? {
							url: "<?php echo base_url();?>data_barang/cek_id",
							type: "post"
						}	: false	)				
					},
                    nama_barang: {
                        required: true,
						remote: (disable != "disabled" ? {
							url: "<?php echo base_url();?>data_barang/cek_name",
							type: "post"
						}	: false	)
                    }
                },
                messages: {
					id_barang:{
						remote: "sudah ada"
					},
					nama_barang:{
						remote: "sudah ada"
					},
                    username: {
                        required: "Fill me please",
                        minlength: "My name is bigger"
                    },
                    password: {
                        required: "Please provide a password",
                        minlength: "My password is more that 6 chars"
                    }
                }   
            });
        });
    </script>